home *** CD-ROM | disk | FTP | other *** search
- TITLE Maximum & Minimum in an Unordered List (EX53.ASM)
- PAGE ,132
- OUR_CODE SEGMENT PARA 'CODE'
- PUBLIC MINMAX
- MINMAX PROC FAR
- ASSUME CS:OUR_CODE
- PUSH CX
- PUSH DI ;Save starting address
- MOV CX,ES:[DI] ;Fetch element count
- DEC CX ;Get ready for count-1 compares
- PUSH CX ;Save this count value
- MOV BX,ES:[DI+2] ;To start, 1st el. is minimum
- MOV AX,BX ; and maximum
- ;
- ; These instructions find the minimum value in the list.
- ;
- ADD DI,4 ;Point to 2nd element
- PUSH DI ; and save this pointer
- CHKMIN: CMP ES:[DI],BX ;Compare next el. to minimum
- JAE NOMIN ;New minimum found?
- MOV BX,ES:[DI] ; Yes. Put it in BX
- NOMIN: ADD DI,2 ;Point to next element
- LOOP CHKMIN
- ;
- ; These instructions find the maximum value in the list.
- ;
- POP DI ;Point to 2nd element
- POP CX ;Reload comparison counter
- CHKMAX: CMP ES:[DI],AX ;Compare next el. to maximum
- JBE NOMAX ;New maximum found?
- MOV AX,ES:[DI] ; Yes. Put it in AX
- NOMAX: ADD DI,2 ;Point to next element
- LOOP CHKMAX ;Check entire list
- POP DI ;Restore starting address
- POP CX
- RET ; and exit
- MINMAX ENDP
- OUR_CODE ENDS
- END MINMAX
-